import mongoose, { Document, Schema } from 'mongoose'

export interface IChatMessage extends Document {
  room: Schema.Types.ObjectId
  user: Schema.Types.ObjectId
  content: string
  type: 'text' | 'gift' | 'system'
  createdAt: Date
}

const ChatMessageSchema = new Schema(
  {
    room: { type: Schema.Types.ObjectId, ref: 'Room', required: true },
    user: { type: Schema.Types.ObjectId, ref: 'User', required: true },
    content: { type: String, required: true },
    type: { type: String, enum: ['text', 'gift', 'system'], default: 'text' },
  },
  {
    timestamps: true,
  }
)

export const ChatMessage = mongoose.model<IChatMessage>('ChatMessage', ChatMessageSchema)
